package com.global.college.ui.presenter;

import android.content.Context;

import com.global.college.api.ProgressSubscriber;
import com.global.college.base.BasePresenter;
import com.global.college.ui.interfaces.IModifyPswView;
import com.global.college.utils.RxTimer;


/**
 * 修改密码
 */
public class ModifyPswPresenter extends BasePresenter {

    private IModifyPswView mIModifyPswView;
    private RxTimer rxTimer;
    private boolean isVisible = true;
    public ModifyPswPresenter(Context context) {
        super(context);
    }

    public void setModifyPswView(IModifyPswView modifyPswView) {
        mIModifyPswView = modifyPswView;
    }
    /**
     * 忘记密码
     *
     * @param
     */
    public void findPsw(String phone,String code,String password) {
        mAuthRequestClient.findPsw( phone, code, password).subscribe(new ProgressSubscriber<Object>(mContext, true) {
            @Override
            public void onNext(Object resetPswModel) {
                if (null != mIModifyPswView) {
                    mIModifyPswView.onFindPswSuccess(resetPswModel);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIModifyPswView){
                    mIModifyPswView.onFindPswFail(e.getMessage());
                }
            }
        });
    }

    /**
     * 获取验证码
     *
     * @param
     */
    public void getSmsCode(String phone) {
        mAuthRequestClient.getSmsCode(phone).subscribe(new ProgressSubscriber<Object>(mContext, true) {
            @Override
            public void onNext(Object smsModel) {
                if (null != mIModifyPswView) {
                    mIModifyPswView.onGetSmsCodeSuccess(smsModel);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIModifyPswView){
                    mIModifyPswView.onGetSmsCodeFail(e.getMessage());
                }
            }
        });
    }


    /**
     * 修改密码
     *
     * @param
     */
    public void editPsw(String confirmPassword,String newPassword,String oldPassword,String userName) {
        mAuthRequestClient.editPsw( confirmPassword, newPassword, oldPassword, userName).subscribe(new ProgressSubscriber<Object>(mContext, true) {
            @Override
            public void onNext(Object object) {
                if (null != mIModifyPswView) {
                    mIModifyPswView.editPwdSuccess(object);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mIModifyPswView.editPwdFail(e.getMessage());
            }
        });
    }
}
